package com.qian.apiserver.controller;

import com.qian.apiserver.model.MatchImageModel;
import com.qian.apiserver.model.User;

import com.qian.apiserver.service.IUserService;
import com.yaowk.api.common.PageReq;
import com.yaowk.api.common.PageResp;
import com.yaowk.api.model.DateQuery;
import com.yaowk.service.system.entity.SysUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.regex.Pattern;

//完成
@RestController("GmUserController")
@RequestMapping("/game/user")
@Api(tags = "用户信息")
public class UserController {
    @Autowired
    private IUserService userService;


    @GetMapping("/all")
    @ApiOperation("列表")
    public PageResp<User> findAll(PageReq pageReq){
        PageResp<User> pageResp = userService.findAll(pageReq);
        return pageResp;
    }
    @PostMapping("/{id}")
    @ApiOperation("修改用户信息")
    public void save(@PathVariable Integer id) {
        User user = userService.findById(id);
        user.setPassword("000000");
        userService.save(user);
    }


    @GetMapping("/query")
    @ApiOperation("用户编号和状态查询")
    public PageResp<User> find(PageReq pageReq,User user){
        if (!StringUtils.isEmpty(user.getUsername())) {
            Pattern pattern = Pattern.compile("[0-9]*");
            if (pattern.matcher(user.getUsername()).matches()) {
                user.setUserCode(Long.parseLong(user.getUsername()));
                user.setUsername("");
                return userService.find(pageReq,user);
            }
        }
        return userService.find(pageReq,user);
    }

}
